package com.tledu.course.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.tledu.course.domain.TleduCourse;
import com.tledu.course.service.ITleduCourseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 天亮云课堂课程管理Controller
 * 
 * @author rupert_tears
 * @date 2021-07-12
 */
@Controller
@RequestMapping("/course/course")
public class TleduCourseController extends BaseController
{
    private String prefix = "course/course";

    private final ITleduCourseService tleduCourseService;

    public TleduCourseController(ITleduCourseService tleduCourseService) {
        this.tleduCourseService = tleduCourseService;
    }

    @RequiresPermissions("course:course:view")
    @GetMapping()
    public String course()
    {
        return prefix + "/course";
    }

    /**
     * 查询天亮云课堂课程管理列表
     */
    @RequiresPermissions("course:course:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TleduCourse tleduCourse)
    {
        startPage();
        List<TleduCourse> list = tleduCourseService.selectTleduCourseList(tleduCourse);
        return getDataTable(list);
    }

    /**
     * 导出天亮云课堂课程管理列表
     */
    @RequiresPermissions("course:course:export")
    @Log(title = "天亮云课堂课程管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TleduCourse tleduCourse)
    {
        List<TleduCourse> list = tleduCourseService.selectTleduCourseList(tleduCourse);
        ExcelUtil<TleduCourse> util = new ExcelUtil<TleduCourse>(TleduCourse.class);
        return util.exportExcel(list, "天亮云课堂课程管理数据");
    }

    /**
     * 新增天亮云课堂课程管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存天亮云课堂课程管理
     */
    @RequiresPermissions("course:course:add")
    @Log(title = "天亮云课堂课程管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TleduCourse tleduCourse)
    {
        return toAjax(tleduCourseService.insertTleduCourse(tleduCourse));
    }

    /**
     * 修改天亮云课堂课程管理
     */
    @GetMapping("/edit/{courseId}")
    public String edit(@PathVariable("courseId") Long courseId, ModelMap mmap)
    {
        TleduCourse tleduCourse = tleduCourseService.selectTleduCourseById(courseId);
        mmap.put("tleduCourse", tleduCourse);
        return prefix + "/edit";
    }

    /**
     * 修改保存天亮云课堂课程管理
     */
    @RequiresPermissions("course:course:edit")
    @Log(title = "天亮云课堂课程管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TleduCourse tleduCourse)
    {
        return toAjax(tleduCourseService.updateTleduCourse(tleduCourse));
    }

    /**
     * 删除天亮云课堂课程管理
     */
    @RequiresPermissions("course:course:remove")
    @Log(title = "天亮云课堂课程管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tleduCourseService.deleteTleduCourseByIds(ids));
    }
}
